package com.dstz.bpm.plugin.usercalc.samenode.executer;

import cn.hutool.core.collection.CollectionUtil;
import com.dstz.bpm.api.engine.plugin.def.BpmUserCalcPluginDef;
import com.dstz.bpm.api.model.task.IBpmTaskOpinion;
import com.dstz.bpm.core.manager.BpmTaskOpinionManager;
import com.dstz.bpm.core.model.BpmTaskOpinion;
import com.dstz.bpm.engine.model.BpmIdentity;
import com.dstz.bpm.engine.plugin.runtime.abstact.AbstractUserCalcPlugin;
import com.dstz.bpm.engine.plugin.session.BpmUserCalcPluginSession;
import com.dstz.bpm.plugin.usercalc.samenode.def.SameNodePluginDef;
import com.dstz.sys.api.model.SysIdentity;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Component;

@Component
public class SameNodePluginExecutor extends AbstractUserCalcPlugin<SameNodePluginDef> {
   @Resource
   BpmTaskOpinionManager y;

   @Override
   public List<SysIdentity> queryByPluginDef(BpmUserCalcPluginSession pluginSession, SameNodePluginDef sameNodeDef) {
      List<SysIdentity> bpmIdentities = new ArrayList();
      List<BpmTaskOpinion> taskOpinionList = this.y.getByInstAndNode(pluginSession.getBpmTask().getInstId(), sameNodeDef.getNodeId());
      if (CollectionUtil.isEmpty(taskOpinionList)) {
         return bpmIdentities;
      } else {
         IBpmTaskOpinion taskOpinion = (IBpmTaskOpinion)taskOpinionList.get(taskOpinionList.size() - 1);
         SysIdentity bpmIdentity = new BpmIdentity(taskOpinion.getApprover(), taskOpinion.getApproverName(), "user");
         bpmIdentities.add(bpmIdentity);
         return bpmIdentities;
      }
   }

   @Override
   public boolean supportPreView() {
      return false;
   }
}
